package cn.zhuo.knowledge.util.transmittable;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * <p>
 *
 * @author z2huo
 */
class IntegerHolder {

    private static final TransmittableThreadLocal<Integer> INTEGER_THREAD_LOCAL = TransmittableThreadLocal.withInitial(() -> 0);

    public static Integer get() {
        return INTEGER_THREAD_LOCAL.get();
    }

    public static void set(Integer value) {
        INTEGER_THREAD_LOCAL.set(value);
    }

    public static void increment() {
        Integer i = INTEGER_THREAD_LOCAL.get();
        INTEGER_THREAD_LOCAL.set(i + 1);
    }

    public static void decrement() {
        Integer i = INTEGER_THREAD_LOCAL.get();
        INTEGER_THREAD_LOCAL.set(i - 1);
    }

    public static void remove() {
        INTEGER_THREAD_LOCAL.remove();
    }

}
